package br.ufpe.cin.dsoa.qos.prohandler;

import java.util.ArrayList;
import java.util.Dictionary;
import java.util.List;

import org.apache.felix.ipojo.metadata.Element;

import br.ufpe.cin.dsoa.qos.Constants;
import br.ufpe.cin.dsoa.qos.Expression;
import br.ufpe.cin.dsoa.qos.Slo;

public class ProviderMetadata {

	private String    proPid;
	private String    proName;
	private List<Slo> slos;
	private String    durationUnit;
	private double    durationValue;
	
	ProviderMetadata(){
		this.slos = new ArrayList<Slo>();
	}

	@SuppressWarnings("rawtypes")
	public void createMetadata(Element metadata, Dictionary configuration){

		/**
		 *Get offer information
		 */
		
		Element[] elementsPro = metadata.getElements(ConstantsProvider.NAME, ConstantsProvider.NAMESPACE);
		
			//setProName(elementsPro[0].getAttribute(Constants.PROVIDER_NAME));
			setProPid(elementsPro[0].getAttribute("pid"));
		/**
		 *Get elements slos
		 */
			
			Element[] elementsSlo = elementsPro[0].getElements(Constants.SLO_ELEMENT);
			for(Element sloEle : elementsSlo){
				
				//name
				String attribute = sloEle.getAttribute(Constants.SLO_ATTRIBUTE_ATTRIBUTE);
				
				//value
				double value = Double.parseDouble(sloEle.getAttribute(Constants.SLO_VALUE_ATTRIBUTE));
				
				//expression
				String expression = sloEle.getAttribute(Constants.SLO_EXPRESSION_ATTRIBUTE);
				
				//target
				String operation = sloEle.getAttribute(Constants.SLO_OPERATION_ATTRIBUTE);
				
				// statistic
				String statistic = sloEle.getAttribute(Constants.SLO_STATISTIC_ATTRIBUTE);
				
				Slo  slo = new Slo(attribute, value, operation, statistic);
				
				getSlos().add(slo);
					
			}
		
	}

	public String getProPid() {
		return proPid;
	}

	public void setProPid(String proPid) {
		this.proPid = proPid;
	}

	public String getProName() {
		return proName;
	}

	public void setProName(String proName) {
		this.proName = proName;
	}

	public void setDurationValue(double durationValue) {
		this.durationValue = durationValue;
	}

	public List<Slo> getSlos() {
		return slos;
	}

	
	
	
}
